/*===========================================================================
Project: 	INCREASING THE DEMAND FOR WORKERS WITH A CRIMINAL RECORD
Info: 		Creates all tables for paper.
Program: 	4_appendixtables.do
Created: 	January 4, 2022
Edited:  	July 12, 2022
Purpose: 	Creates main tables for paper on workers with a criminal conviction at the Platform.
Note: 		Set the working directory to the Replication folder that contains this do file.
===========================================================================*/
cap log close
clear all  
version 16, permanently 
discard 

* Install Packages
ssc install gtools, replace
ssc install egenmore, replace
ssc install estout, replace
ssc install distinct, replace
net install multe, from("https://raw.githubusercontent.com/gphk-metrics/stata-multe/main/") replace

***** Set paths.
global Main "`c(pwd)'"
cd "$Main"

* Data directory
global Data "$Main/analysis_data"

* Table directory 
global Tables "$Main/output_tables"

* set seed
set seed 89449
set sortseed 12345


/*==================================================================
*** RUN A LOG FILE ***
==================================================================*/
global date = "$S_DATE"
global LogPath = "$Main/log"
capture log close
log using "$LogPath/WCC_$date.log", append

/*==================================================================
*** LOAD PROGRAMS ***
==================================================================*/
/***
Program: coef_store
Purpose: format and store coefficients from regression
***/
program define coef_store, rclass

syntax anything(name=var), /// 
[fmt(string)] /// /* optional argument to modify the format */
[STARs] /// /* dummy to include stars */
[notex] /* pull out LaTeX formatting */  

if "`tex'" != "notex"{
    local l = "$^{"
    local r = "}$"
}

if missing("`fmt'") local fmt "%10.3fc"

lincom `var'
local b = string(r(estimate), "`fmt'") 
local se = "(" + string(r(se), "`fmt'") + ")"
local p = r(p)

local star=""
if `p' >.05 & `p' <=.10 {   
    local star = "`l'*`r'"
}
if `p' >.01 & `p' <=.05 {   
    local star = "`l'**`r'"
}
if `p' <=.01 {  
    local star = "`l'***`r'" 
}

local p_val= string(`p', "`fmt'")
tokenize "`fmt'", parse(".fgc")
local digits = `3'

if `p' < (10^-`digits')  local p_val= "$<$" + string(10^-`digits', "`fmt'")

if `"`se'"' == `"0"' & `"`b'"' == `"0"' { 
    local b "\multicolumn{1}{c}{--}" 
    local se "" 
}

* if !missing("`star'") local star "$`star'$"
if "`stars'" != "stars" local star "" 


return local beta = "`b'`star'"
return local se = "`se'"
return local p = "`p_val'"


end

/***
Program: get_obs
Purpose: gets number of unique firms
***/
program get_obs, rclass
syntax if 

qui: count `if'
local obs = `r(N)'

local n_firms = 0
qui: levelsof firm_id `if', local(firms)

foreach f of local firms{
    local ++n_firms
}

return local counts = "`=string(`obs', "%10.0gc")'" 
return local firms = "`=string(`n_firms', "%10.0gc")'" 

end 

/***
Program: store_estimates
Purpose: stores estimates from regressions
***/
program define store_estimates, rclass

args var

if "`var'" == "lincom" {
    local b = string(r(estimate), "%10.3fc") 
    local se = "(" + string(r(se), "%10.3fc") + ")"
}
else {
    local b = string(_b[`var'], "%10.3fc") 
    local se = "(" + string(_se[`var'], "%10.3fc") + ")"
}

/* local p = 2*(1-normal(abs(_b[`var']/_se[`var']))) */
local p = 2*(1-normal(abs(`b'/`se')))

local star=""
if `p' >.05 & `p' <=.10 {   
    local star = "^{*}"
}
if `p' >.01 & `p' <=.05 {   
    local star = "^{**}"
}
if `p' <=.01 {  
    local star = "^{***}" 
}
local p_val=string(`p', "%10.3fc")

if `se' == `b' & `se' == 0 { 
    local b "\multicolumn{1}{c}{--}" 
    local se "" 
}

return local beta = "`b'"
return local se = "`se'"
/* if !missing("`star'") return local star = "$`star'$" */
return local pvalue= "`p_val'"


end


/***
Program: stepdown
Purpose: Runs Westfall–Young stepdown procedure to test for dependence.
***/
program stepdown, rclass

syntax anything(id="model list" name=commands everything), ///
[Reps(integer 10000)] /// /* set number of bootstrap draws  */
[BS_sample(integer -1)] /// /* set bootstrap sample size  */
[echo] /// option to control if it should display every bootstrap iteration 
[STRata(passthru) CLuster(passthru) IDcluster(passthru) Weight(passthru)] /* passthru args for bootstrap */


local passed_bs_sample = `bs_sample'

if `bs_sample' == -1 local bs_sample

tempname pmat adj_mat model_names sdCoefIds bs_pvals
global sdPVal `pmat'
global sdPAdjusted `adj_mat'
global sdCoefIds `sdCoefIds'
global sdBootPVals `bs_pvals'

global sdCoefList 
global sdModelIndex 1


local input_command_list `commands'

/* Get the initial list of p-values */
while "`commands'" != ""{
	gettoken cmd commands : commands, parse(" ||") bind match(parenthesis)

	/* di as text "Executing command: " as input `"`cmd'"' */

	qui: store_pvalues `cmd' mat($sdPVal)

	/* keep track of the number of models */
	global sdModelIndex = ${sdModelIndex}+1
}



/* Make sure we can label the matrix with the right names after we sort them */
local n_rows : list sizeof global(sdCoefList)
matrix $sdCoefIds = 1 
forvalues i = 2/`n_rows'{
	matrix $sdCoefIds = $sdCoefIds \ `i'
}


/* Sort the p-values to be ascending */
mata p = st_matrix("$sdPVal")
mata ids = st_matrix("$sdCoefIds")
mata ordered = sort((p,ids), 1)
mata st_matrix("$sdPVal", ordered[,1])
mata st_matrix("$sdCoefIds", ordered[,2])

/* Relabel now that we've sorted  */
local sorted_coef_list 
forvalues i = 1/`n_rows'{
	local id = $sdCoefIds[`i',1]
	local name :word `id' of $sdCoefList
	local sorted_coef_list `sorted_coef_list' `=strtrim("`name'")'
}  

matrix rownames $sdPVal  = `sorted_coef_list'

******************** BEGIN BOOTSTRAP *****************


/* now we bootstrap and re-estimate the coefficient vector */
forvalues bs_index = 1/`reps'{
	preserve 

	if !missing("`echo'") di as text "bootstrap iteration `bs_index'"
	// we support all the passthrough args for bsample 
	if !missing("`strata'`cluster'`idcluster'`weight'") local comma ","
	bsample `bs_sample' `comma' `strata' `cluster' `idcluster' `weight' 

	/* get the original list of commands to loop through */
	local commands `input_command_list'

	global sdCoefList ""
	global sdModelIndex 1

	/* loop through commands to get the bootstrapped p-values */
	while "`commands'" != "" {
		gettoken cmd commands : commands, parse(" ||") bind match(parenthesis)

		qui: store_pvalues `cmd' mat($sdBootPVals)

		/* keep track of the number of models */
		global sdModelIndex = ${sdModelIndex}+1
	}

	matrix rownames $sdBootPVals  = $sdCoefList

	tempname bs_ordered 
	mat_order `bs_ordered' : $sdBootPVals $sdPVal
	// di "ordered"
	// mat list `bs_ordered'

	/* di "`: rowfullnames `bs_ordered''"   */

	/* stepdown from max to min to enforce monotonicity*/
	forvalues r = `=`n_rows'-1'(-1)1{ // start in the second-to-last row
	/* "cascade" small values down, so that monotonicity is enforced
	- i.e. no entry can be larger than the entries below it */
		mat `bs_ordered'[`r',1] = min(`bs_ordered'[`r'+1,1], `bs_ordered'[`r',1]) 
	}
	// di "monotonicity enforced"
	// mat list `bs_ordered'

	mata p_bs_col = st_matrix("`bs_ordered'")
	// mata p_bs_col
	if `bs_index' == 1 mata p_bs = p_bs_col
	else mata p_bs = p_bs, p_bs_col

	/* mat list `bs_ordered' */

	mat drop $sdBootPVals
	restore
}

mata raw_p =  ordered[,1]

* di "bootstrapped"
* mata p_bs 

* di "unadjusted"
* mata raw_p 

mata adj_p =  p_bs :<= raw_p
* di "matrix: bootstrapped <=unadjusted"
* mata adj_p 
mata adj_p = rowsum(adj_p) :/ rownonmissing(adj_p)

* di "vector: adjusted "
* mata adj_p 

mata st_matrix("$sdPAdjusted", adj_p)

/* step-up */
forvalues r = 2/`n_rows'{ // start in the second row
/* "cascade" large values up, so that monotonicity is enforced
- i.e. no entry can be smaller than the entries below it */
	mat $sdPAdjusted[`r',1] = max($sdPAdjusted[`r'-1,1], $sdPAdjusted[`r',1]) 
}

tempname orig_order
mat `orig_order' = J(`n_rows',1,.) 
mat rownames `orig_order' = $sdCoefList

matrix rownames $sdPAdjusted  = `sorted_coef_list'

mat_order $sdPVal : $sdPVal `orig_order'
mat_order $sdPAdjusted : $sdPAdjusted `orig_order'

return matrix p = $sdPVal
return matrix adj_p = $sdPAdjusted

end 

***********************************************************************************************
**************** HELPER FUNCTION TO EXTRACT P-VALUES AFTER RUNNING COMMANDS *******************
***********************************************************************************************

/* internal function */
program store_pvalues 

syntax anything(id="model" name=command everything) [pweight fweight iweight aweight], ///
ADJust(string) ///
mat(name) ///
[*] // allow for arbitrary command-specific options 

if !missing(`"`exp'"') local clean_weight `"[`weight'`exp']"'

if "`options'" != "" local options , `options'
`command' `clean_weight' `options'

/* check if the p-value matrix exists */
cap qui mat list `mat'
local make_mat = _rc != 0

/* if it doesn't exist, we need to initialize it */
if `make_mat'{
	local x1 : word 1 of `adjust'

	qui: lincom `x1'
	mat `mat' = (r(p))
}


foreach var of local adjust{
	global sdCoefList ${sdCoefList} [m${sdModelIndex}:`var']

	if `make_mat' {
		/* skip the first variable if we've just created the matrix using it */
		local make_mat 0
		continue 
	}

	qui lincom `var'
	mat `mat' = (`mat'\r(p))    
}

end 

/*==================================================================
*** MAKE TABLES ***
==================================================================*/

/*===========================================================================
Appendix Table B.2: Summary Statisitcs For Platform Firms By Survey Response
===========================================================================*/

local n_categories = 11 // max = 11 
local n_industries = 9

* First, we want to get the data that we have in the panel itself 
use "$Data/main_survey_wide.dta", clear 

* Generate variable for number of job ratings posted or jobs with start dates in 2019
gen num_months_post_2019 = (jan2019 > 0 & !missing(jan2019)) + (feb2019 > 0 & !missing(feb2019)) + (mar2019 > 0 & !missing(mar2019)) + (apr2019 > 0 & !missing(apr2019)) + (may2019 > 0 & !missing(may2019)) + (jun2019 > 0 & !missing(jun2019)) + (jul2019 > 0 & !missing(jul2019)) + (aug2019 > 0 & !missing(aug2019)) + (sep2019 > 0 & !missing(sep2019)) + (oct2019 > 0 & !missing(oct2019)) + (nov2019 > 0 & !missing(nov2019)) + (dec2019 > 0 & !missing(dec2019))
replace num_months_post_2019 = . if missing(jan2019) | missing(feb2019) | missing(mar2019) | missing(apr2019) | missing(may2019) | missing(jun2019) | missing(jul2019) | missing(aug2019) | missing(sep2019) | missing(oct2019) | missing(nov2019) | missing(dec2019)

* Locals for number of managers
count 
local all_mgrs = string(`r(N)',"%9.3gc")

count if !missing(sic1)
local ind_mgrs = string(`r(N)',"%9.3gc")

count if !missing(estab_age) | !missing(empsize)
local age_mgrs = string(`r(N)',"%9.3gc")

egen nmissingWCC1 = rowmiss(wcc_policy shrm_best_candidate shrm_second_chance shrm_incentivized shrm_customers shrm_regulations shrm_performance)
gen nmissingWCC = nmissingWCC1 == 0 
count if nmissingWCC
local WCC_mgrs = string(`r(N)',"%9.3gc") 

* Collapse by firm_id
collapse (firstnm) industry sic1 (mean) platform_tenure estab_age empsize wcc_policy shrm_best_candidate shrm_second_chance shrm_incentivized shrm_customers shrm_regulations shrm_performance months_on_platform num_months_post_2019 (sum) n_jobs, by(firm_id)

************************************************
** Column 1: Data from the panel 
***********************************************
*** Characteristics of firms and managers in sample
* Locals for number of firms
count if !missing(industry)
local ind_obs = string(`r(N)',"%9.3gc")

count if !missing(estab_age) | !missing(empsize)
local age_obs = string(`r(N)',"%9.3gc")

count
local total_obs = string(`r(N)',"%9.3gc")

** Panel A
* Median firm age
gquantiles estab_age, _pctile percentile(50)
local firmAge = string(r(r1),"%04.1f")

* Median firm size
gquantiles empsize, _pctile percentile(50)
local firmSize = string(r(r1),"%9.1g")

* Mean number of active firms in 2019
gen active_2019 = n_jobs > 0
sum active_2019
local firmShareActive = string(r(mean),"%3.2f")

* Mean number of jobs in 2019
sum n_jobs 
local firmnjobs = string(r(mean),"%14.3gc")

* Total number of active firms in 2019
count if num_months_post_2019 > 0
local firmtotalactive = string(`r(N)',"%9.3gc")

* Median number of active months in 2019
gquantiles num_months_post_2019, _pctile percentile(50)
local firmActivity = string(r(r1),"%04.1g")

* Industry shares
tab industry, sort gen(ind) 

forvalues ind = 1/`n_industries' {
su ind`ind', meanonly
local indshare`ind' =string(`r(mean)', "%03.2f")

tokenize "`: variable label ind`ind''", parse("==")
local indlabel`ind' = "`3'"
}

** Panel B 
* Share of firms with WC policy
foreach var in wcc_policy shrm_best_candidate shrm_second_chance shrm_incentivized shrm_customers shrm_regulations shrm_performance{
su `var', meanonly
local `var' = string(r(mean),"%3.2f")
}
egen nmissingWCC1 = rowmiss(wcc_policy shrm_best_candidate shrm_second_chance shrm_incentivized shrm_customers shrm_regulations shrm_performance)
gen nmissingWCC = nmissingWCC1 == 0 
count if nmissingWCC
local WCC_obs = string(`r(N)',"%9.3gc")

* Platform tenure
su platform_tenure, meanonly
local yearsonplatform = string(`r(mean)'/12, "%4.1f")

* Number of observations
count
local obs = string(`r(N)',"%9.3gc")


*** Characteristics of firms and managers not in the sample
use "$Data/platform_infogroup.dta", clear
tab surveyed
count if surveyed == 0
return list
local not_surveyed = `r(N)'
preserve
keep if surveyed == 0

* Age, firm size, platform tenure
gquantiles estab_age, _pctile percentile(50)
local platform_firmAge = string(r(r1),"%04.1f")

gquantiles empsize, _pctile percentile(50)
local platform_firmSize = string(r(r1),"%9.1g")
sum empsize
gquantiles platform_tenure, _pctile percentile(50)
local platform_yearsonplatform = string(r(r1), "%4.1f")

* Firm activity
gquantiles num_months_post_2019, _pctile percentile(50)
local platform_Activity = string(r(r1), "%4.1g")
gen active_2019 = n_jobs > 0
sum active_2019
local platform_ShareActive = string(r(mean),"%3.2f")
sum n_jobs, d
local platform_njobs = string(r(mean),"%9.1g")
count if num_months_post_2019 > 0
local platform_totalactive = string(`r(N)',"%9.3gc")

* Industry shares
forvalues ind = 1/9 {
gen ind`ind' = industry == `"`indlabel`ind''"' if !missing(industry)

su ind`ind', meanonly
local platform_indshare`ind' =string(`r(mean)', "%03.2f")
}
gen firm_id = _n
get_obs if !missing(estab_age) | !missing(empsize)
local platform_obs = "`r(counts)'"
local platform_firms = "`r(firms)'"

count if !missing(industry) 
local platform_ind = string(`r(N)',"%14.3gc")
restore 

* Generate LaTeX file for the table
file open fh using "$Tables/xt2_summarystats_platform_firms.tex", write replace

file write fh ///
"\begin{table}[htpb!]" _n /// 
"\centering" _n ///
"\caption{\\ Descriptive Statistics of Firms on the Platform by Survey Response}" _n ///
"\label{table_compare_survey}"	_n /// 
"\small\begin{tabular}{l ccc }" _n ///
"\toprule" _n

file write fh ///
									"	&   \multicolumn{1}{c}{Responded}  	&&  \multicolumn{1}{c}{Did Not Respond} \\" _n ///  
			"Firm Characteristics	&   \multicolumn{1}{c}{to Survey}  		&&  \multicolumn{1}{c}{to Survey} \\" _n ///  
"\cmidrule(lr){2-2} \cmidrule(lr){4-4}" _n ///
"\hspace{5 pt} Median Firm Age 						& `firmAge' 							&& `platform_firmAge' 	   \\" _n ///  
"\hspace{5 pt} Median Number of Employees						& `firmSize'							&& `platform_firmSize'	   \\" _n /// 
"\hspace{5 pt} `indlabel1' 						& `indshare1'							&& `platform_indshare1'	   \\" _n ///
"\hspace{5 pt} `indlabel2' 						& `indshare2'							&& `platform_indshare2'	   \\" _n ///
"\hspace{5 pt} `indlabel3' 						& `indshare3'							&& `platform_indshare3'	   \\" _n ///
"\hspace{5 pt} `indlabel4' 						& `indshare4'							&& `platform_indshare4'	   \\" _n ///
"\hspace{5 pt} `indlabel5' 						& `indshare5'							&& `platform_indshare5'	   \\" _n ///
"\hspace{5 pt} `indlabel6' 						& `indshare6'							&& `platform_indshare6'	   \\" _n ///
"\hspace{5 pt} `indlabel7' 						& `indshare7'							&& `platform_indshare7'	   \\" _n ///
"\hspace{5 pt} `indlabel8' 						& `indshare8'							&& `platform_indshare8'	   \\" _n ///
"\hspace{5 pt} `indlabel9' 						& `indshare9'							&& `platform_indshare9'	   \\" _n ///
"\addlinespace" _n ///
"Firms with Nonmissing Age or Number Employees											& `age_obs' 							&& `platform_obs'	   		\\" _n ///
"\hspace{5 pt} with Nonmissing Industry Classification 		& `ind_obs'								&& `platform_ind'	   		\\" _n ///
"\addlinespace" _n ///
"Mean Number of Jobs Posted 		& `firmnjobs'								&& `platform_njobs'	   		\\" _n ///
"\addlinespace" _n ///

file write fh ///
"\bottomrule  " _n /// 
"\end{tabular}" _n /// 
"\begin{tabular}{p{0.95\textwidth}}" _n /// 
"\footnotesize{\hspace{1em}{\emph{Notes.}}" _n /// 
"This table compares descriptive statistics for the experimental sample comprised of the 1,095 hiring " _n /// 
"managers from 913 businesses that completed the experiment to that of the `not_surveyed' firms on the Platform that did not respond to the survey." _n /// 
"The industry characteristics are further limited to the firms in our sample with that data available in the Infogroup Database. The data used to calculate mean number of jobs posted extends from 2018 to the beginning of 2020." _n ///
"}" _n /// 
"\end{tabular}" _n /// 
"\end{table}"  _n _n _n _n _n 

file close fh
macro drop fh

/*=================================================================
Appendix Table B.3: Descriptives by Hire and Subsidy            
=================================================================*/
use "$Data/main_survey_wide.dta", clear 

* Industry indicators
drop service
gen service = industry == "Service" if !missing(industry)
gen manufact = industry == "Manufacturing" if !missing(industry)
gen retail  = industry == "Retail" if !missing(industry)
gen finance  = industry == "Finance, Insurance, \& Real Estate" if !missing(industry)
gen construction  = industry == "Construction" if !missing(industry)
gen wholesale  = industry == "Wholesale Trade" if !missing(industry)
gen transp  = industry == "Transportation \& Public Utilities" if !missing(industry)

* Other survey questions
gen behavior = strpos(how_others_hire , "Behavior by employees with criminal records") > 0
gen perform_well_binary = perform_well_num >= 2.5
gen put_others_at_risk_binary = put_others_at_risk_num >= 2.5
gen steal_cause_damage_binary = steal_cause_damage_num >= 2.5

replace n_jobs = 0 if missing(n_jobs)

* Descriptive variables
local descriptive_vars exp_hire empsize n_jobs service manufact retail wcc_policy shrm_best_candidate shrm_second_chance shrm_incentivized behavior shrm_customers shrm_regulations shrm_performance ///
perform_well_binary put_others_at_risk_binary steal_cause_damage_binary construction finance wholesale transp

* Loop through descriptive variables to calculate means and p-values comparing hiring and non-hiring groups
forvalues i = 1/`: word count `descriptive_vars'' {
local var: word `i' of `descriptive_vars'
local fmt %03.2f
if inlist(`i',2,3) 	local fmt %9.0fc
reg `var' ibn.subsidy_rate#ibn.hire_sub, nocons cluster(firm_id) 

foreach sub in 0 10 25 50 100 {
foreach D in 1 0 {

coef_store `sub'.subsidy_rate#`D'.hire_sub, fmt("`fmt'")

local `var'_B `"``var'_B' & `r(beta)'"'
local `var'_se `"``var'_se' & `r(se)'"'
}
}
test (0.subsidy_rate#0.hire_sub  = 	0.subsidy_rate#1.hire_sub) ///
(10.subsidy_rate#0.hire_sub  = 	10.subsidy_rate#1.hire_sub) ///
(25.subsidy_rate#0.hire_sub  = 	25.subsidy_rate#1.hire_sub) ///
(50.subsidy_rate#0.hire_sub  = 	50.subsidy_rate#1.hire_sub) ///
(100.subsidy_rate#0.hire_sub = 	100.subsidy_rate#1.hire_sub)

local disp_P = substr(string(r(p), "%04.3f"), 2, .)
if r(p) < 0.001 local disp_P = "<.001"

count if e(sample)
local N = string(r(N), "%9.0fc")

local `var'_B `"``var'_B' & `disp_P' & `N'"'
}

label variable exp_hire "Years Experience of Hiring Manager"
label variable empsize "Employees"
label variable n_jobs "N. Jobs Posted on Platform"
label variable service " Service"
label variable manufact " Manufacturing"
label variable retail " Retail"
label variable finance " Finance, Insurance, \& Real Estate"
label variable construction " Construction"
label variable wholesale " Wholesale"
label variable transp " Transportation \& Public Utilities "

**** Confidence/concerns 
label var perform_well_binary "Confidence a WC will Perform Well"
label var put_others_at_risk_binary "Concern a WC will Put Others at Risk"
label var steal_cause_damage_binary "Concern a WC will Steal or Cause Damage"


**** SHRM answers 
// wcc_policy shrm_best_candidate shrm_second_chance shrm_incentivized shrm_customers shrm_regulations shrm_performance ///
label variable wcc_policy "Firm-Wide WC Hiring Policy"

label variable shrm_best_candidate "Consider WCs Because Best Candidate"
label variable shrm_second_chance "Consider WCs Because Second Chances Are Important"
label variable shrm_incentivized "Consider WCs Because of Financial Incentives"

label variable shrm_customers "Concerned About Customer Reactions"
label variable shrm_performance "Concerned About Performance"
label variable shrm_regulations "Concerned About Local, State, or Federal Regulations"

* Generate LaTeX file for the table
file open fh using "$Tables/xt3_demanddescriptives.tex", write replace

file write fh ///
"\begin{landscape}" /// 
"\begin{table}[htpb!]" _n ///
"\vspace*{-1cm}" _n ///
"\centering" _n ///	
"\captionsetup{justification=centering}" _n ///
"\caption{\\ Descriptive Statistics by Subsidy Level and Willingness to Hire WCs}" _n ///
"\label{table_demand_descriptives} " _n ///
"\scriptsize\begin{tabular}{l cc cc cc cc cc cc}" _n ///
"\toprule " _n ///
"& \multicolumn{10}{c}{Wage Subsidy} \\ " _n ///											
"\cmidrule(lr){2-11}" _n ///
"& \multicolumn{2}{c}{No Subsidy} & \multicolumn{2}{c}{10\% Subsidy} & \multicolumn{2}{c}{25\% Subsidy} & \multicolumn{2}{c}{50\% Subsidy} & \multicolumn{2}{c}{100\% Subsidy} \\ " _n ///											
"\cmidrule(lr){2-3}\cmidrule(lr){4-5}\cmidrule(lr){6-7}\cmidrule(lr){8-9}\cmidrule(lr){10-11}" _n ///
"& \multicolumn{2}{c}{Work w/ WCs?}& \multicolumn{2}{c}{Work w/ WCs?}& \multicolumn{2}{c}{Work w/ WCs?}& \multicolumn{2}{c}{Work w/ WCs?}& \multicolumn{2}{c}{Work w/ WCs?} \\  " _n ///											
"A. Firm Characteristics & Yes & No & Yes & No & Yes & No & Yes & No & Yes & No & p(F-stat) & N \\" _n ///
"\cmidrule(lr){2-2} \cmidrule(lr){3-3} \cmidrule(lr){4-4} \cmidrule(lr){5-5} \cmidrule(lr){6-6} \cmidrule(lr){7-7} \cmidrule(lr){8-8} \cmidrule(lr){9-9} \cmidrule(lr){10-10} \cmidrule(lr){11-11} \cmidrule(lr){12-12} \cmidrule(lr){13-13} " _n

foreach var in exp_hire empsize n_jobs service manufact retail transp wholesale  finance construction   wcc_policy {
file write fh "\hspace{1em} `:variable label `var'' ``var'_B' \\" _n 
file write fh " ``var'_se' \\" _n 
}

file write fh "\addlinespace B. Policies Concerning Whether WCs can Work \\ " _n 

foreach var in shrm_best_candidate shrm_second_chance shrm_incentivized {
file write fh "\hspace{1em} `:variable label `var'' ``var'_B' \\" _n 
file write fh " ``var'_se' \\" _n 
}

foreach var in shrm_customers shrm_performance shrm_regulations {
file write fh "\hspace{1em} `:variable label `var'' ``var'_B' \\" _n 
file write fh " ``var'_se' \\" _n 
}

file write fh "\addlinespace C. WC Perceptions, Binary Scale \\ " _n 

foreach var in 	perform_well_binary put_others_at_risk_binary steal_cause_damage_binary {
file write fh "\hspace{1em} `:variable label `var'' ``var'_B' \\" _n 
file write fh " ``var'_se' \\" _n 
}

file write fh ///
"\bottomrule" _n /// 
"\end{tabular}" _n ///
"\begin{tabular}{ p{\linewidth}}"  _n ///
"\footnotesize{\hspace{1em}{\emph{Notes.}}" _n ///
"Each row presents means of some attribute for each subsidy level, split by whether the respondent is willing to work with a WC at that subsidy level." _n ///
"Standard deviations are in parentheses." _n ///
"Column 11 shows the \$p\$-value calculated using robust standard errors clustered by business that is associated with the F-statistic from the test that the means are equal for the hiring and not hiring groups at every subsidy level." _n ///
"Column 12 shows the number of respondents for whom the attribute of interest is available." _n /// 
"See the Table \ref{table_summarystats} notes for additional details on the outcomes and sample. " _n ///
"}"  _n /// 
"\end{tabular}" _n ///
"\end{table}" _n ///
"\end{landscape}" _n


file close fh 
macro drop fh 

/*===========================================================================
Appendix Table B.4: Contamination Bias
============================================================================*/

use "$Data/main_survey_long.dta", clear

* Calculate decomposition for insurance treatment
multe hire_ins ins_cap, control(subsidy_rate) decomp

mat decomp = e(decomposition)

local rows = `=rowsof(decomp)' / 2
local cols = `=colsof(decomp)'

forvalues i = 1/`rows' {
forvalues j = 1/`cols' {
local ins_coef_`i'_`j' = string(decomp[2*`i'-1,`j'], "%10.3fc")
local ins_se_`i'_`j' = string(decomp[2*`i', `j'], "%10.3fc")
}
}

* Calculate decomposition for job history treatment
multe hire_hist past_jobs, control(subsidy_rate) decomp

mat decomp = e(decomposition)

local rows = `=rowsof(decomp)' / 2
local cols = `=colsof(decomp)'
forvalues i = 1/`rows' {
forvalues j = 1/`cols' {
local hist_coef_`i'_`j' = string(decomp[2*`i'-1,`j'], "%10.3fc")
local hist_se_`i'_`j' = string(decomp[2*`i', `j'], "%10.3fc")
}
}

* Calculate decomposition for limited crim. record screening
multe hire_clean years_elapsed, control(subsidy_rate) decomp

mat decomp = e(decomposition)

local rows = `=rowsof(decomp)' / 2
local cols = `=colsof(decomp)'
forvalues i = 1/`rows' {
forvalues j = 1/`cols' {
local clean_coef_`i'_`j' = string(decomp[2*`i'-1,`j'], "%10.3fc")
local clean_se_`i'_`j' = string(decomp[2*`i', `j'], "%10.3fc")
}
}

* Generate LaTeX file for the table
cap erase "$Tables/xt4_contamination_bias.tex"
file open fh using "$Tables/xt4_contamination_bias.tex", write append

file write fh "\begin{table}[htpb!]" _n //
file write fh " \vspace*{-1cm}" _n //
file write fh " \centering" _n //
file write fh "\captionsetup{justification=centering}" _n //
file write fh "\caption{ \\ Contamination Bias in the Full-Sample Estimates}" _n //
file write fh "\label{table_contamination}" _n //
file write fh "\small\begin{tabular}{l c c c c c c c c c}" _n //
file write fh "\toprule " _n //
file write fh " & \multicolumn{1}{c}{Full-Sample} && \multicolumn{1}{c}{Own} && \multicolumn{1}{c}{Contamination} && \multicolumn{3}{c}{Worst-Case Bias} \\ " _n //
file write fh "\cline{8-10} "

file write fh "A. Crime and Safety Insurance &  \multicolumn{1}{c}{Estimate} && \multicolumn{1}{c}{Effect} && \multicolumn{1}{c}{Bias} && \multicolumn{1}{c}{Negative} && \multicolumn{1}{c}{Positive} \\ " _n //
file write fh " \cline{2-2}\cline{4-4}\cline{6-6}\cline{8-8}\cline{10-10}" _n //
file write fh "\addlinespace" _n //
file write fh "\hspace{5 pt} \\$5k$^\dagger$ & `ins_coef_1_1' && `ins_coef_1_2' && `ins_coef_1_3' && `ins_coef_1_4' && `ins_coef_1_5' \\" _n //
file write fh " 	& (`ins_se_1_1') && (`ins_se_1_2') && (`ins_se_1_3') && (`ins_se_1_4') && (`ins_se_1_5') \\" _n //
file write fh "\hspace{5 pt} \\$100k & `ins_coef_2_1' && `ins_coef_2_2' && `ins_coef_2_3' && `ins_coef_2_4' && `ins_coef_2_5' \\" _n //
file write fh "     & (`ins_se_2_1') && (`ins_se_2_2') && (`ins_se_2_3') && (`ins_se_2_4') && (`ins_se_2_5') \\" _n //
file write fh "\hspace{5 pt} \\$5m & `ins_coef_3_1' && `ins_coef_3_2' && `ins_coef_3_3' && `ins_coef_3_4' && `ins_coef_3_5' \\" _n //
file write fh "     & (`ins_se_3_1') && (`ins_se_3_2') && (`ins_se_3_3') && (`ins_se_3_4') && (`ins_se_3_5') \\" _n //

file write fh "\addlinespace B. Job History Screening &  && && && && \\    " _n //
file write fh "\hspace{5 pt} 1 Job & `hist_coef_1_1' && `hist_coef_1_2' && `hist_coef_1_3' && `hist_coef_1_4' && `hist_coef_1_5' \\" _n //
file write fh " 	& (`hist_se_1_1') && (`hist_se_1_2') && (`hist_se_1_3') && (`hist_se_1_4') && (`hist_se_1_5') \\" _n //
file write fh "\hspace{5 pt} 5 Jobs & `hist_coef_2_1' && `hist_coef_2_2' && `hist_coef_2_3' && `hist_coef_2_4' && `hist_coef_2_5' \\" _n //
file write fh "     & (`hist_se_2_1') && (`hist_se_2_2') && (`hist_se_2_3') && (`hist_se_2_4') && (`hist_se_2_5') \\" _n //
file write fh "\hspace{5 pt} 25 Jobs & `hist_coef_3_1' && `hist_coef_3_2' && `hist_coef_3_3' && `hist_coef_3_4' && `hist_coef_3_5' \\" _n //
file write fh "     & (`hist_se_3_1') && (`hist_se_3_2') && (`hist_se_3_3') && (`hist_se_3_4') && (`hist_se_3_5') \\" _n //

file write fh "\addlinespace C. Limited Record Screening &  && && && && \\    " _n //
file write fh "\hspace{5 pt} 1 Year & `clean_coef_1_1' && `clean_coef_1_2' && `clean_coef_1_3' && `clean_coef_1_4' && `clean_coef_1_5' \\" _n //
file write fh " 	& (`clean_se_1_1') && (`clean_se_1_2') && (`clean_se_1_3') && (`clean_se_1_4') && (`clean_se_1_5') \\" _n //
file write fh "\hspace{5 pt} 3 Years & `clean_coef_2_1' && `clean_coef_2_2' && `clean_coef_2_3' && `clean_coef_2_4' && `clean_coef_2_5' \\" _n //
file write fh "     & (`clean_se_2_1') && (`clean_se_2_2') && (`clean_se_2_3') && (`clean_se_2_4') && (`clean_se_2_5') \\" _n //
file write fh "\hspace{5 pt} 7 Years & `clean_coef_3_1' && `clean_coef_3_2' && `clean_coef_3_3' && `clean_coef_3_4' && `clean_coef_3_5' \\" _n //
file write fh "     & (`clean_se_3_1') && (`clean_se_3_2') && (`clean_se_3_3') && (`clean_se_3_4') && (`clean_se_3_5') \\" _n //

file write fh "\addlinespace" _n //
file write fh "\bottomrule" _n //
file write fh "\end{tabular}" _n //

file write fh "\begin{tabular}{ p{\linewidth}}" _n //
file write fh "\footnotesize{\hspace{1em}{\emph{Notes.}} This table reports decompositions of the full-sample estimates into the effect of the given policy " _n //
file write fh "and the contamination bias from the other mutually exclusive policies using the approach developed by Goldsmith-Pinkham, Hull and Koles{\'a}r (2022). %\citet{goldsmithpinkham2022}. " _n //
file write fh "Column 1 reports estimates from the full sample using regression specifications similar to Equation \eqref{eq_delta}. " _n //
file write fh "Columns 2 and 3 report the own- and cross-treatment decompositions of these estimates. " _n //
file write fh "Columns 4 and 5 report the smallest and largest possible contamination biases from different possible correlations between the treatments and wage subsidy controls. " _n //
file write fh "Panel A reports the effect relative to the constant of providing insurance covering damages related to theft or safety up to the indicated level. " _n //
file write fh "Panel B reports the effect relative to the constant of requiring that WCs satisfactorily complete the indicated number of jobs. " _n //
file write fh "Panel C reports the effect relative to the constant of imposing a minimum time since arrest or conviction before allowing WCs to join the pool of workers. " _n //
file write fh "All results report robust (non-clustered) standard errors in parentheses." _n //

file write fh " " _n //
file write fh "$\dagger$ We use different values for crime and safety insurance (\\$1k and \\$5k) in two survey arms. " _n //
file write fh "For exposition, we pool the \\$1k and \\$5k insurance levels, which results in a uniform number of " _n //
file write fh "observations across values displayed under the label \emph{\\$5k}. }\\" _n //
file write fh "\end{tabular}" _n //

file write fh "\end{table}" _n //

file close fh
macro drop fh

/*===========================================================================
Appendix Table B.5: Treatment Effects 
===========================================================================+*/

use "$Data/main_survey_long.dta", clear

* Get Firm Size and Number of Managers 
distinct firm_id 
local n_firms = string(r(ndistinct), "%8.0fc")

distinct mgr_id 
local n_mgrs = string(r(ndistinct), "%8.0fc")

distinct firm_id if subsidy_rate == 0
local n_firms_nosub = string(r(ndistinct), "%8.0fc")

distinct mgr_id if subsidy_rate == 0
local n_mgrs_nosub = string(r(ndistinct), "%8.0fc")

* Get Effects of Treatments
local row=1
mat R=J(30,6,.)

* Crime and safety insurance - no subsidy sample
reg hire_ins i.ins_cap if subsidy_rate == 0, cluster(firm_id) coefl
foreach X in 5000.ins_cap 100000.ins_cap 5000000.ins_cap {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=1
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}

* Job history treatment - no subsidy sample
reg hire_hist i.past_jobs if subsidy_rate == 0, cluster(firm_id) coefl
foreach X in 1.past_jobs 5.past_jobs 25.past_jobs {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=1
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}	

* Limited criminal history screening treatment - no subsidy sample
reg hire_clean i.years_elapsed if subsidy_rate == 0, cluster(firm_id) coefl 
foreach X in 1.years_elapsed 3.years_elapsed 7.years_elapsed {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=1
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}

* Crime and safety insurance - full sample
reg hire_ins i.ins_cap i.subsidy_rate, cluster(firm_id) coefl
foreach X in 5000.ins_cap 100000.ins_cap 5000000.ins_cap {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=1
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}

* Job history screening - full sample
reg hire_hist i.past_jobs i.subsidy_rate, cluster(firm_id) coefl
foreach X in 1.past_jobs 5.past_jobs 25.past_jobs {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=1
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}	

* Limited criminal history screening - full sample
reg hire_clean i.years_elapsed i.subsidy_rate, cluster(firm_id) coefl 
foreach X in 1.years_elapsed 3.years_elapsed 7.years_elapsed {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=1
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}

* Crime and safety insurance - full sample with interactions
reg hire_ins i.ins_cap i.subsidy_rate i.subsidy_rate#5000.ins_cap i.subsidy_rate#100000.ins_cap i.subsidy_rate#5000000.ins_cap, cluster(firm_id)  
foreach X in 5000.ins_cap 100000.ins_cap 5000000.ins_cap {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=1
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}

* Job history screening - full sample with interactions
reg hire_hist i.past_jobs i.subsidy_rate i.subsidy_rate#1.past_jobs i.subsidy_rate#5.past_jobs i.subsidy_rate#25.past_jobs, cluster(firm_id)
foreach X in 1.past_jobs 5.past_jobs 25.past_jobs {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=1
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}	

* Limited criminal history screening - full sample with interactions
reg hire_clean i.years_elapsed i.subsidy_rate i.subsidy_rate#1.years_elapsed i.subsidy_rate#3.years_elapsed i.subsidy_rate#7.years_elapsed, cluster(firm_id) 
foreach X in 1.years_elapsed 3.years_elapsed 7.years_elapsed {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=1
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}

* Get p-value of Joint Significance for Interaction Effects
reg hire_ins i.ins_cap i.subsidy_rate i.subsidy_rate#5000.ins_cap i.subsidy_rate#100000.ins_cap i.subsidy_rate#5000000.ins_cap, cluster(firm_id)  
testparm i.subsidy_rate#i.ins_cap
local p_ins = substr(string(r(p),  "%10.3fc"),  2, .)

reg hire_hist i.past_jobs i.subsidy_rate i.subsidy_rate#1.past_jobs i.subsidy_rate#5.past_jobs i.subsidy_rate#25.past_jobs, cluster(firm_id)  
testparm i.subsidy_rate#i.past_jobs
local p_past = substr(string(r(p),  "%10.3fc"),  2, .)

reg hire_clean i.years_elapsed i.subsidy_rate i.subsidy_rate#1.years_elapsed i.subsidy_rate#3.years_elapsed i.subsidy_rate#7.years_elapsed, cluster(firm_id)  
testparm i.subsidy_rate#i.years_elapsed
local p_yrs = substr(string(r(p),  "%10.3fc") ,  2, .)


* Get FWER-adjusted p-values following Westfall-Young stepdown
use "$Data/main_survey_long.dta", clear

gen ins = ins_cap/1000
rename past_jobs pj 
rename years_elapsed yr

* Full sample main treatment effects Westfall-Young p-values
stepdown ///
(reg hire_ins   i.subsidy_rate i.ins,   cluster(firm_id) ///
adjust(5.ins 100.ins 5000.ins)) /// 
(reg hire_hist  i.subsidy_rate i.pj, cluster(firm_id) ///
adjust(1.pj 5.pj 25.pj)) ///
(reg hire_clean i.subsidy_rate i.yr, cluster(firm_id) /// 
adjust(1.yr 3.yr 7.yr)) , cluster(firm_id) reps(10000)   /// original # reps is 10000

* Extract adjusted p-values based on order of covariates 
matrix list r(adj_p) 
matrix adj_p = r(adj_p) 

local row = 1
foreach i in 5.ins 100.ins 5000.ins {
local wy = substr(string(adj_p[`row',1],"%04.3f"),  2, .)
local l = subinstr("`i'",".","",.)
local l = subinstr("`l'","-","_",.)
local wy_`l' = "[`wy']"
local row = `row' + 1
}

foreach i in 1.pj 5.pj 25.pj {
local wy = substr(string(adj_p[`row',1],"%04.3f"),  2, .) 
local l = subinstr("`i'",".","",.)
local l = subinstr("`l'","-","_",.)
local wy_`l' = "[`wy']"
local row = `row' + 1
}

foreach i in 1.yr 3.yr 7.yr {
local wy = substr(string(adj_p[`row',1],"%04.3f"),  2, .)
local l = subinstr("`i'",".","",.)
local l = subinstr("`l'","-","_",.)
local wy_`l' = "[`wy']"
local row = `row' + 1
}

* No subsidy sample main treatment effects Westfall-Young p-values
stepdown ///
(reg hire_ins   i.ins if subsidy_rate == 0,   cluster(firm_id) ///
adjust(5.ins 100.ins 5000.ins )) /// 
(reg hire_hist  i.pj if subsidy_rate == 0, cluster(firm_id) ///
adjust(1.pj 5.pj 25.pj )) ///
(reg hire_clean i.yr if subsidy_rate == 0, cluster(firm_id) /// 
adjust(1.yr 3.yr 7.yr )) , cluster(firm_id) reps(10000)     /// original # reps is 10000

* Extract adjusted p-values based on order of covariates 
matrix list r(adj_p) 
matrix adj_p = r(adj_p) 

local row = 1
foreach i in 5.ins 100.ins 5000.ins {
local wy0 = substr(string(adj_p[`row',1],"%04.3f"),  2, .)
local l = subinstr("`i'",".","",.)
local l = subinstr("`l'","-","_",.)
local wy0_`l' = "[`wy0']"
local row = `row' + 1
}

foreach i in 1.pj 5.pj 25.pj {
local wy0 = substr(string(adj_p[`row',1],"%04.3f"),  2, .)
local l = subinstr("`i'",".","",.)
local l = subinstr("`l'","-","_",.)
local wy0_`l' = "[`wy0']"
local row = `row' + 1
}

foreach i in 1.yr 3.yr 7.yr  {
local wy0 = substr(string(adj_p[`row',1],"%04.3f"),  2, .) 
local l = subinstr("`i'",".","",.)
local l = subinstr("`l'","-","_",.)
local wy0_`l' = "[`wy0']"
local row = `row' + 1
}

clear	
svmat R
la var R1 "Willingness to Work with WCs (%)"

label define R5 1 "$5k Insurance" 2 "1 Past Job" 3 "1 Year Clean"
label values R5 R5

label define R6 1 "No Subsidy" 2 "Full Sample" 3 "Full Sample w/Interactions"
label values R6 R6

* Generate LaTeX file for the table
capture erase "$Tables/xt5_treatments.tex"
file open fh using "$Tables/xt5_treatments.tex", write append 	

file write fh "\begin{table}[htpb!]" _n //
file write fh " \vspace*{-1cm}" _n //
file write fh " \centering" _n //
file write fh "\captionsetup{justification=centering}" _n //
file write fh "\caption{ \\ Crime and Safety Insurance, Job History, and Limited Criminal Record Screening}" _n //
file write fh "\label{table_treatments}" _n //
file write fh "\small\begin{tabular}{l c c c c c}" _n //
file write fh "\toprule " _n //
file write fh " &  \multicolumn{1}{c}{No Subsidy} && \multicolumn{1}{c}{} && \multicolumn{1}{c}{Full Sample}  \\ " _n //
file write fh "A. Crime and Safety Insurance &  \multicolumn{1}{c}{Sample} && \multicolumn{1}{c}{Full Sample} && \multicolumn{1}{c}{w/ Interactions}  \\ " _n //
file write fh " \cline{2-2}\cline{4-4}\cline{6-6}" _n //
file write fh "\addlinespace" _n //
file write fh "\hspace{5 pt} \\$5k$^\dagger$ & `coef_1' && `coef_10' && `coef_19' \\" _n //
file write fh "    & (`sd_1') && (`sd_10') && (`sd_19') \\" _n //
file write fh "    & `wy0_5ins' && `wy_5ins' && -- \\" _n //
file write fh "    \hspace{5 pt} \\$100k & `coef_2' && `coef_11' && `coef_20' \\" _n //
file write fh "     & (`sd_2') && (`sd_11') && (`sd_20') \\" _n //
file write fh "    & `wy0_100ins' && `wy_100ins' && -- \\" _n //
file write fh "\hspace{5 pt} \\$5m & `coef_3' && `coef_12' && `coef_21' \\" _n //
file write fh "     & (`sd_3') && (`sd_12') && (`sd_21') \\" _n //
file write fh "    & `wy0_5000ins' && `wy_5000ins' && -- \\" _n //
file write fh "\hspace{5 pt} Interactions \$p\$-value & -- && -- && `p_ins' \\" _n //
file write fh "\addlinespace B. Job History Screening &  && &&  \\    " _n //
file write fh "\hspace{5 pt} 1 Job & `coef_4' && `coef_13' && `coef_22' \\" _n //
file write fh "     & (`sd_4') && (`sd_13') && (`sd_22') \\" _n //
file write fh "    & `wy0_1pj' && `wy_1pj' && -- \\" _n //
file write fh "\hspace{5 pt} 5 Jobs & `coef_5' && `coef_14' && `coef_23' \\" _n //
file write fh "     & (`sd_5') && (`sd_14') && (`sd_23') \\" _n //
file write fh "    & `wy0_5pj' && `wy_5pj' && -- \\" _n //
file write fh "\hspace{5 pt} 25 Jobs & `coef_6' && `coef_15' && `coef_24' \\" _n //
file write fh "     & (`sd_6') && (`sd_15') && (`sd_24') \\" _n //
file write fh "    & `wy0_25pj' && `wy_25pj' && -- \\" _n //
file write fh "\hspace{5 pt} Interactions \$p\$-value & -- && -- && `p_past' \\" _n //
file write fh "\addlinespace C. Limited Record Screening &  && &&  \\    " _n //
file write fh "\hspace{5 pt} 1 Year & `coef_7' && `coef_16' && `coef_25' \\" _n //
file write fh "     & (`sd_7') && (`sd_16') && (`sd_25') \\" _n //
file write fh "    & `wy0_1yr' && `wy_1yr' && -- \\" _n //
file write fh "\hspace{5 pt} 3 Years & `coef_8' && `coef_17' && `coef_26' \\" _n //
file write fh "     & (`sd_8') && (`sd_17') && (`sd_26') \\" _n //
file write fh "    & `wy0_3yr' && `wy_3yr' && -- \\" _n //
file write fh "\hspace{5 pt} 7 Years & `coef_9' && `coef_18' && `coef_27' \\" _n //
file write fh "     & (`sd_9') && (`sd_18') && (`sd_27') \\" _n //
file write fh "    & `wy0_7yr' && `wy_7yr' && -- \\" _n //
file write fh "\hspace{5 pt} Interactions \$p\$-value & -- && -- && `p_yrs' \\" _n //
file write fh "\addlinespace" _n //
file write fh "\hline" _n //
file write fh "\addlinespace" _n //
file write fh "Firms       & `n_firms_nosub'   && `n_firms' && 	`n_firms'          \\" _n //
file write fh "Managers    & `n_mgrs_nosub' && `n_mgrs' && `n_mgrs'  \\" _n //
file write fh "\bottomrule" _n //
file write fh "\end{tabular}" _n //
file write fh "\begin{tabular}{ p{\linewidth}}" _n //
file write fh "\footnotesize{\hspace{1em}{\emph{Notes.}} This table reports OLS estimates of the effects of different policies" _n //
file write fh "on firms' willingness to work with workers with a criminal record. Column 1 reports results for the sample of" _n //
file write fh "`n_mgrs_nosub' hiring managers from `n_firms_nosub' businesses in the no wage subsidy sample. Column 2 reports results for the full" _n //
file write fh "sample of `n_mgrs' hiring managers from `n_firms' businesses that completed the experiment. Column 3 reports results for the full sample with controls for interaction effects. The interactions \$p\$-values reported in column 3 are for the joint significance of the interaction effects and are calculated using robust standard errors clustered by business." _n //
file write fh "Panel A reports the effect relative to the baseline of providing insurance covering damages related to theft or safety up to the indicated level. " _n //
file write fh "Panel B reports the effect relative to the baseline of requiring that WCs satisfactorily complete the indicated number of jobs. " _n //
file write fh "Panel C report the effect relative to the baseline of imposing a minimum time since arrest or conviction before allowing WCs to join the pool of workers. " _n //
file write fh "All specifications report standard errors clustered by business in parentheses." _n //
file write fh "Westfall-Young adjusted \$p\$-values are reported in brackets." _n //
file write fh " " _n //
file write fh "$\dagger$ We use different values for crime and safety insurance (\\$1k and \\$5k) in two survey arms. " _n //
file write fh "For exposition, we pool the \\$1k and \\$5k insurance levels, which results in a uniform number of " _n //
file write fh "observations across values displayed under the label \emph{\\$5k}. }\\" _n //
file write fh "\end{tabular}" _n //
file write fh "\end{table}" _n //

file close fh
macro drop fh	


/*===========================================================================
Appendix Table B.6: Effects by Conviction Type
===========================================================================+*/

use "$Data/main_survey_longcrime.dta", clear

* Remove baseline observations since we are calculating effects relative to violent felony and not relative to baseline
gen no_conviction_restriction = violent_fel != 1 & prop_fin_fel != 1 & substance_fel != 1 & violent_mis != 1 & prop_fin_mis != 1 & substance_mis != 1 
drop if no_conviction_restriction == 1

distinct firm_id 
local n_firms = string(r(ndistinct), "%8.0fc")

distinct mgr_id 
local n_mgrs = string(r(ndistinct), "%8.0fc")

distinct firm_id if subsidy_rate == 0
local n_firms_nosub = string(r(ndistinct), "%8.0fc")

distinct mgr_id if subsidy_rate == 0
local n_mgrs_nosub = string(r(ndistinct), "%8.0fc")

local row=1
mat R=J(20,5,.)

* Get effects of restricting to conviction types relative to violent felony restriction - no subsidy sample
reg hire violent_mis prop_fin_fel prop_fin_mis substance_fel substance_mis if subsidy_rate == 0, cluster(firm_id) 
foreach X in violent_mis prop_fin_fel prop_fin_mis substance_fel substance_mis {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}	

* Get effects of restricting to conviction types relative to violent felony restriction - full sample
reg hire violent_mis prop_fin_fel prop_fin_mis substance_fel substance_mis i.subsidy_rate, cluster(firm_id) 
foreach X in violent_mis prop_fin_fel prop_fin_mis substance_fel substance_mis {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=2
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}	

* Get effects of restricting to conviction types relative to violent felony restriction - full sample w/ interactions
reg hire i.subsidy_rate ///
violent_mis prop_fin_fel prop_fin_mis  ///
substance_fel substance_mis ///
10.subsidy_rate#prop_fin_fel 25.subsidy_rate#prop_fin_fel 50.subsidy_rate#prop_fin_fel 100.subsidy_rate#prop_fin_fel ///
10.subsidy_rate#substance_fel 25.subsidy_rate#substance_fel 50.subsidy_rate#substance_fel 100.subsidy_rate#substance_fel ///
10.subsidy_rate#violent_mis 25.subsidy_rate#violent_mis 50.subsidy_rate#violent_mis 100.subsidy_rate#violent_mis ///
10.subsidy_rate#prop_fin_mis 25.subsidy_rate#prop_fin_mis 50.subsidy_rate#prop_fin_mis 100.subsidy_rate#prop_fin_mis ///
10.subsidy_rate#substance_mis 25.subsidy_rate#substance_mis 50.subsidy_rate#substance_mis 100.subsidy_rate#substance_mis , cluster(firm_id)	
foreach X in violent_mis prop_fin_fel prop_fin_mis substance_fel substance_mis {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=3
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}	


* Get p-value of Joint Significance for Interaction Effects
testparm 10.subsidy_rate#prop_fin_fel 25.subsidy_rate#prop_fin_fel 50.subsidy_rate#prop_fin_fel 100.subsidy_rate#prop_fin_fel  10.subsidy_rate#substance_fel 25.subsidy_rate#substance_fel 50.subsidy_rate#substance_fel 100.subsidy_rate#substance_fel 10.subsidy_rate#violent_mis 25.subsidy_rate#violent_mis 50.subsidy_rate#violent_mis 100.subsidy_rate#violent_mis  10.subsidy_rate#prop_fin_mis 25.subsidy_rate#prop_fin_mis 50.subsidy_rate#prop_fin_mis 100.subsidy_rate#prop_fin_mis  10.subsidy_rate#substance_mis 25.subsidy_rate#substance_mis 50.subsidy_rate#substance_mis 100.subsidy_rate#substance_mis  

local p_crime = substr(string(r(p),"%10.3fc"),  2, .)


* Get FWER-adjusted p-values using Westfall-Young algorithm
use "$Data/main_survey_long.dta", clear
append using "$Data/main_survey_longcrime.dta"

rename (violent_fel prop_fin_fel substance_fel violent_mis prop_fin_mis substance_mis) ///
(vf pf sf vm pm sm)

* Full sample Westfall-Young p-values
stepdown ///
(reg hire vf pf sf vm pm sm i.subsidy_rate,  cluster(firm_id) ///
adjust(pf-vf sf-vf vm-vf pm-vf sm-vf)), cluster(firm_id) reps(10000)     /// original # reps is 10000

* Extract adjusted p-values based on order of covariates 
matrix list r(adj_p) 
matrix adj_p = r(adj_p) 

local row = 1
foreach cr in pf-vf sf-vf vm-vf pm-vf sm-vf {
local wy = substr(string(adj_p[`row',1],"%04.3f"),  2, .)
local l = subinstr("`cr'",".","",.)
local l = subinstr("`l'","-","_",.)
local wy_`l' "[`wy']"
local row = `row' + 1
}

* No subsidy sample main treatment Westfall-Young p-values
stepdown ///
(reg hire vf pf sf vm pm sm if subsidy_rate == 0,  cluster(firm_id) ///
adjust(pf-vf sf-vf vm-vf pm-vf sm-vf)), cluster(firm_id) reps(10000)     /// original # reps is 10000

* Extract adjusted p-values based on order of covariates 
matrix list r(adj_p) 
matrix adj_p = r(adj_p) 

local row = 1
foreach cr in pf-vf sf-vf vm-vf pm-vf sm-vf {
local wy0 = substr(string(adj_p[`row',1],"%04.3f"),  2, .)
local l = subinstr("`cr'",".","",.)
local l = subinstr("`l'","-","_",.)
local wy0_`l' "[`wy0']"
local row = `row' + 1
}

* Generate LaTeX file for the table
clear
svmat R
la var R1 "Willingness to Work with WCs (%)"


label define R5 1 "No Subsidy" 2 "Full Sample" 3 "Full Sample w/Interactions" 
label values R5 R5

capture erase "$Tables/xt6_convictions.tex"
file open fh using "$Tables/xt6_convictions.tex", write append 	

file write fh "\begin{table}[htpb!]" _n //
file write fh " \vspace*{-1cm}" _n //
file write fh " \centering" _n //
file write fh "\captionsetup{justification=centering}" _n //
file write fh "\caption{ \\ Criminal Record Screening by Conviction Type}" _n //
file write fh "\label{table_convictions}" _n //
file write fh "\small\begin{tabular}{l c c c c c}" _n //
file write fh "\toprule " _n //
file write fh " &  \multicolumn{1}{c}{No Subsidy} && \multicolumn{1}{c}{} && \multicolumn{1}{c}{Full Sample}  \\ " _n //
file write fh " &  \multicolumn{1}{c}{Sample} && \multicolumn{1}{c}{Full Sample} && \multicolumn{1}{c}{w/ Interactions}  \\ " _n //
file write fh " \cline{2-2}\cline{4-4}\cline{6-6}" _n //
file write fh "\addlinespace" _n //
file write fh "\hspace{5 pt} Violent Misdemeanor & `coef_1' && `coef_6' && `coef_11' \\" _n //
file write fh "     & (`sd_1') && (`sd_6') && (`sd_11') \\" _n //
file write fh "    & `wy0_vm_vf' && `wy_vm_vf' && -- \\" _n //
file write fh "\hspace{5 pt} Property Felony & `coef_2' && `coef_7' && `coef_12' \\" _n //
file write fh "     &  (`sd_2') && (`sd_7') && (`sd_12') \\" _n //
file write fh "    & `wy0_pf_vf' && `wy_pf_vf' && -- \\" _n //
file write fh "\hspace{5 pt} Property Misdemeanor & `coef_3' && `coef_8' && `coef_13' \\" _n //
file write fh "     &  (`sd_3') && (`sd_8') && (`sd_13') \\" _n //
file write fh "    & `wy0_pm_vf' && `wy_pm_vf' && -- \\" _n //
file write fh "\hspace{5 pt} Drug Felony & `coef_4' && `coef_9' && `coef_14' \\" _n //
file write fh "     & (`sd_4') && (`sd_9') && (`sd_14') \\" _n //
file write fh "    & `wy0_sf_vf' && `wy_sf_vf' && -- \\" _n //
file write fh "\hspace{5 pt} Drug Misdemeanor &  `coef_5' && `coef_10' && `coef_15' \\" _n //
file write fh "     &  (`sd_5') && (`sd_10') && (`sd_15') \\" _n //
file write fh "    & `wy0_sm_vf' && `wy_sm_vf' && -- \\" _n //
file write fh "\hspace{5 pt} Interactions \$p\$-value & -- && -- && `p_crime' \\" _n //
file write fh "\addlinespace" _n //
file write fh "\hline" _n //
file write fh "\addlinespace" _n //
file write fh "Firms       & `n_firms_nosub'   && `n_firms' && 	`n_firms'          \\" _n //
file write fh "Managers    & `n_mgrs_nosub' && `n_mgrs' && `n_mgrs'  \\" _n //
file write fh "\bottomrule" _n //
file write fh "\end{tabular}" _n //
file write fh "\begin{tabular}{ p{\linewidth}}" _n //
file write fh "\footnotesize{\hspace{1em}{\emph{Notes.}} This table reports OLS estimates of the effects of restricting WCs to those with a given crime type on firms' willingness to work with workers with a criminal record. The effects are relative to the fraction of respondents willing to work with WCs if the Platform restricts WCs to those who had a violent felony conviction. Column 1 reports results for the sample of" _n //
file write fh "`n_mgrs_nosub' hiring managers from `n_firms_nosub' businesses in the no wage subsidy sample. Column 2 reports results for the full" _n //
file write fh "sample of `n_mgrs' hiring managers from `n_firms' businesses that completed the experiment. Column 3 reports results for the full sample with controls for interaction effects. The interactions \$p\$-values reported in Column 3 are for the joint significance of the interaction effects and are calculated using robust standard errors clustered by business." _n //
file write fh "All specifications report standard errors clustered by business in parentheses. " _n //
file write fh "Westfall-Young adjusted \$p\$-values are reported in brackets. }\\" _n //
file write fh "\end{tabular}" _n //
file write fh "\end{table} " _n //

file close fh
macro drop fh	

/*===========================================================================
Appendix Table B.7: Robustness
============================================================================*/

use "$Data/main_survey_long.dta", clear

* Merge in indicator for subsample
preserve
use "$Data/reweight_by_infogroup_industry_firmsize.dta", clear 
keep if subsample == 1 
keep mgr_id firm_id subsample
tempfile subsamp
save `subsamp'
restore 
merge m:1 mgr_id firm_id using `subsamp'	

* Merge in SHRM weights
preserve
use "$Data/reweight_by_infogroup_industry_firmsize.dta", clear 
keep if reweight_shrm == 1 
keep mgr_id firm_id weight 
rename weight weight_shrm
tempfile shrm
save `shrm'
restore 
drop _merge	
merge m:1 mgr_id firm_id using `shrm'	

* Merge in Infogroup weights
preserve
use "$Data/reweight_by_infogroup_industry_firmsize.dta", clear 
keep if reweight_info == 1 
keep mgr_id firm_id weight 
rename weight weight_info
tempfile info
save `info'
restore 
drop _merge		
merge m:1 mgr_id firm_id using `info'	

* Calculate number of managers and number of firms for each type of robustness check
distinct mgr_id if subsample == 1 & subsidy_rate == 0
local n_mgrs_nosub_subsample = string(r(ndistinct), "%8.0fc")

distinct firm_id if subsample == 1 & subsidy_rate == 0
local n_firms_nosub_subsample = string(r(ndistinct), "%8.0fc")

distinct mgr_id if subsample == 1 
local n_mgrs_subsample = string(r(ndistinct), "%8.0fc")

distinct firm_id if subsample == 1 	
local n_firms_subsample = string(r(ndistinct), "%8.0fc")

* Unilateral authority - no subsidy sample
local row=13
mat R=J(100,6,.)

* Subsample - no subsidy sample
reg hire_ins i.ins_cap if subsidy_rate == 0 & subsample == 1, cluster(firm_id)
foreach X in 5000.ins_cap 100000.ins_cap 5000000.ins_cap _cons {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=2
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}
reg hire_hist i.past_jobs if subsidy_rate == 0 & subsample == 1, cluster(firm_id) 
foreach X in 1.past_jobs 5.past_jobs 25.past_jobs _cons {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=2
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}	
reg hire_clean i.years_elapsed if subsidy_rate == 0 & subsample == 1, cluster(firm_id) 
foreach X in 1.years_elapsed 3.years_elapsed 7.years_elapsed _cons {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=2
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}

* SHRM re-weighting - no subsidy sample
reg hire_ins i.ins_cap if subsidy_rate == 0 [aw=weight_shrm], cluster(firm_id)
foreach X in 5000.ins_cap 100000.ins_cap 5000000.ins_cap _cons {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=3
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}
reg hire_hist i.past_jobs if subsidy_rate == 0 [aw=weight_shrm], cluster(firm_id) 
foreach X in 1.past_jobs 5.past_jobs 25.past_jobs _cons {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=3
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}	
reg hire_clean i.years_elapsed if subsidy_rate == 0 [aw=weight_shrm], cluster(firm_id) 
foreach X in 1.years_elapsed 3.years_elapsed 7.years_elapsed _cons {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=3
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}

* Infogroup reweighting - no subsidy sample
reg hire_ins i.ins_cap if subsidy_rate == 0 [aw=weight_info], cluster(firm_id)
foreach X in 5000.ins_cap 100000.ins_cap 5000000.ins_cap _cons {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=4
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}
reg hire_hist i.past_jobs if subsidy_rate == 0 [aw=weight_info], cluster(firm_id) 
foreach X in 1.past_jobs 5.past_jobs 25.past_jobs _cons {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=4
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}	
reg hire_clean i.years_elapsed if subsidy_rate == 0 [aw=weight_info], cluster(firm_id) 
foreach X in 1.years_elapsed 3.years_elapsed 7.years_elapsed _cons {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=4
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}

local row=`row'+12

* Subsample - full sample
reg hire_ins i.ins_cap i.subsidy_rate if subsample == 1, cluster(firm_id)
foreach X in 5000.ins_cap 100000.ins_cap 5000000.ins_cap _cons {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=6
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}
reg hire_hist i.past_jobs i.subsidy_rate if subsample == 1, cluster(firm_id) 
foreach X in 1.past_jobs 5.past_jobs 25.past_jobs _cons {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=6
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}	
reg hire_clean i.years_elapsed i.subsidy_rate if subsample == 1, cluster(firm_id) 
foreach X in 1.years_elapsed 3.years_elapsed 7.years_elapsed _cons {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=6
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}

* SHRM re-weighting - full sample
reg hire_ins i.ins_cap i.subsidy_rate [aw=weight_shrm], cluster(firm_id)
foreach X in 5000.ins_cap 100000.ins_cap 5000000.ins_cap _cons {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=7
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}
reg hire_hist i.past_jobs i.subsidy_rate [aw=weight_shrm], cluster(firm_id) 
foreach X in 1.past_jobs 5.past_jobs 25.past_jobs _cons {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=7
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}	
reg hire_clean i.years_elapsed i.subsidy_rate [aw=weight_shrm], cluster(firm_id)
foreach X in 1.years_elapsed 3.years_elapsed 7.years_elapsed _cons {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=7
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}

* Infogroup re-weighting - full sample
reg hire_ins i.ins_cap i.subsidy_rate [aw=weight_info], cluster(firm_id)
foreach X in 5000.ins_cap 100000.ins_cap 5000000.ins_cap _cons {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=8
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}
reg hire_hist i.past_jobs i.subsidy_rate [aw=weight_info], cluster(firm_id)
foreach X in 1.past_jobs 5.past_jobs 25.past_jobs _cons {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=8
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}			
reg hire_clean i.years_elapsed i.subsidy_rate [aw=weight_info], cluster(firm_id) 
foreach X in 1.years_elapsed 3.years_elapsed 7.years_elapsed _cons {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=8
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}

clear	
svmat R
la var R1 "Willingness to Work with WCs (%)"

label define R5 1 "$5k Insurance" 2 "1 Past Job" 3 "1 Year Clean"
label values R5 R5

label define R6 1 "Restricted Sample - No Subsidy" 2 "Reweighted by WC Policy - No Subsidy" 3 "Reweighted by Industry Shares and Firm Size - No Subsidy" 4 "Unilateral Discretion - Full Sample" 5 "Restricted Sample - Full Sample" 6 "Reweighted by WC Policy - Full Sample" 7 "Reweighted by Industry Shares and Firm Size - Full Sample"
label values R6 R6

* Generate LaTeX file for the table
capture erase "$Tables/xt7_robustness.tex"
file open fh using "$Tables/xt7_robustness.tex", write append 	
file write fh "\begin{landscape}" _n //
file write fh "\begin{table}[htpb!]" _n //
file write fh " \vspace*{-1cm}" _n //
file write fh " \centering" _n //
file write fh "\captionsetup{justification=centering}" _n //
file write fh "\caption{ \\ Reweighted Main Results}" _n //
file write fh "\label{table_robustness}" _n //
file write fh "\footnotesize\begin{tabular}{l c c c c c c c c c c c}" _n //
file write fh "\toprule " _n //
file write fh "& \multicolumn{5}{c}{No Subsidy Sample} && \multicolumn{5}{c}{Full Sample} \\" _n //
file write fh "\cline{2-6} \cline{8-12}" _n //
file write fh "\addlinespace" _n //
file write fh " & \multicolumn{1}{c}{} && \multicolumn{1}{c}{Reweighted} && \multicolumn{1}{c}{Reweighted} && \multicolumn{1}{c}{} && \multicolumn{1}{c}{Reweighted} && \multicolumn{1}{c}{Reweighted}  \\ " _n //
file write fh "&  \multicolumn{1}{c}{} && \multicolumn{1}{c}{by WC} && \multicolumn{1}{c}{by Industry} && \multicolumn{1}{c}{} && \multicolumn{1}{c}{by WC} && \multicolumn{1}{c}{by Industry}  \\ " _n //
file write fh "& \multicolumn{1}{c}{Restricted} && \multicolumn{1}{c}{Hiring} && \multicolumn{1}{c}{Shares and} && \multicolumn{1}{c}{Restricted} && \multicolumn{1}{c}{Hiring} && \multicolumn{1}{c}{Shares and}  \\ " _n //
file write fh "A. Crime and Safety Insurance & \multicolumn{1}{c}{Sample} && \multicolumn{1}{c}{ Policy} && \multicolumn{1}{c}{Firm Size} && \multicolumn{1}{c}{Sample} && \multicolumn{1}{c}{ Policy} && \multicolumn{1}{c}{Firm Size}  \\ " _n //
file write fh " \cline{2-2}\cline{4-4}\cline{6-6}\cline{8-8}\cline{10-10}\cline{12-12}" _n //
file write fh "\addlinespace" _n //
file write fh "\hspace{5 pt} \\$5k$^\dagger$ & `coef_13' && `coef_25' && `coef_37' && `coef_61' && `coef_73' && `coef_85'  \\" _n //
file write fh "    	&  (`sd_13') && (`sd_25') && (`sd_37')  && (`sd_61') && (`sd_73') && (`sd_85')  \\" _n //
file write fh "\hspace{5 pt} \\$10k &  `coef_14' && `coef_26' && `coef_38' && `coef_62' && `coef_74' && `coef_86'   \\" _n //
file write fh "     &  (`sd_14') && (`sd_26') && (`sd_38') && (`sd_62') && (`sd_74') && (`sd_86')   \\" _n //
file write fh "\hspace{5 pt} \\$5m &  `coef_15' && `coef_27' && `coef_39' && `coef_63' && `coef_75' && `coef_87'   \\" _n //
file write fh "     & (`sd_15') && (`sd_27') && (`sd_39') && (`sd_63') && (`sd_75') && (`sd_87')   \\" _n //
file write fh "\hspace{5 pt} Constant &  `coef_16' && `coef_28' && `coef_40' && `coef_64' && `coef_76' && `coef_88'   \\" _n //
file write fh "     &  (`sd_16') && (`sd_28') && (`sd_40') && (`sd_64') && (`sd_76') && (`sd_88')   \\" _n //
file write fh "\addlinespace B. Job History Screening & &&   &&  &&  &&  &&   \\    " _n //
file write fh "\hspace{5 pt} 1 Job & `coef_17' && `coef_29'  && `coef_41' && `coef_65' && `coef_77' && `coef_89'  \\" _n //
file write fh "     & (`sd_17') && (`sd_29') && (`sd_41') && (`sd_65') && (`sd_77') && (`sd_89')   \\" _n //
file write fh "\hspace{5 pt} 5 Jobs & `coef_18' && `coef_30' && `coef_42' && `coef_66' && `coef_78' && `coef_90'   \\" _n //
file write fh "     & (`sd_18') && (`sd_30') && (`sd_42') && (`sd_66') && (`sd_78') && (`sd_90')   \\" _n //
file write fh "\hspace{5 pt} 25 Jobs & `coef_19' && `coef_31' && `coef_43' && `coef_67' && `coef_79' && `coef_91'   \\" _n //
file write fh "     & (`sd_19') && (`sd_31') && (`sd_43') && (`sd_67') && (`sd_79') && (`sd_91')   \\" _n //
file write fh "\hspace{5 pt} Constant &  `coef_20' && `coef_32' && `coef_44' && `coef_68' && `coef_80' && `coef_92'   \\" _n //
file write fh "     &  (`sd_20') && (`sd_32') && (`sd_44') && (`sd_68') && (`sd_80') && (`sd_92')   \\" _n //
file write fh "\addlinespace C. Limited Record Screening & && && &&  &&  &&     \\    " _n //
file write fh "\hspace{5 pt} 1 Year & `coef_21' && `coef_33' && `coef_45' && `coef_69' && `coef_81' && `coef_93'   \\" _n //
file write fh "     & (`sd_21') && (`sd_33') && (`sd_45') && (`sd_69') && (`sd_81') && (`sd_93')   \\" _n //
file write fh "\hspace{5 pt} 3 Years & `coef_22' && `coef_34' && `coef_46' && `coef_70' && `coef_82' && `coef_94'   \\" _n //
file write fh "     &  (`sd_22') && (`sd_34') && (`sd_46') && (`sd_70') && (`sd_82') && (`sd_94')   \\" _n //
file write fh "\hspace{5 pt} 7 Years & `coef_23' && `coef_35' && `coef_47' && `coef_71' && `coef_83' && `coef_95'   \\" _n //
file write fh "     &  (`sd_23') && (`sd_35') && (`sd_47') && (`sd_71') && (`sd_83') && (`sd_95')   \\" _n //
file write fh "\hspace{5 pt} Constant & `coef_24' && `coef_36' && `coef_48' && `coef_72' && `coef_84' && `coef_96'   \\" _n //
file write fh "     &  (`sd_24') && (`sd_36') && (`sd_48') && (`sd_72') && (`sd_84') && (`sd_96')   \\" _n //
file write fh "\addlinespace" _n //
file write fh "\hline" _n //
file write fh "\addlinespace" _n //
file write fh "Firms       & `n_firms_nosub_subsample' && `n_firms_nosub_subsample' && `n_firms_nosub_subsample' && `n_firms_subsample' && `n_firms_subsample' && `n_firms_subsample'       \\" _n //
file write fh "Managers    & `n_mgrs_nosub_subsample' && `n_mgrs_nosub_subsample' && `n_mgrs_nosub_subsample' && `n_mgrs_subsample' && `n_mgrs_subsample' && `n_mgrs_subsample'   \\" _n //
file write fh "\bottomrule" _n //
file write fh "\end{tabular}" _n //
file write fh "\begin{tabular}{ p{\linewidth}}" _n //
file write fh "\scriptsize{\hspace{1em}{\emph{Notes.}} This table reports OLS estimates of the effects of different policies on firms' willingness to work with workers with a criminal record using different samples and weighting methods. In each panel, the constant is the estimate for the mean willingness to work with WCs with no treatment and no subsidy. " _n //
file write fh "Panel A reports the effect relative to the constant of providing insurance covering damages related to theft or safety up to the indicated level. " _n //
file write fh "Panel B reports the effect relative to the constant of requiring that WCs satisfactorily complete the indicated number of jobs. " _n //
file write fh "Panel C reports the effect relative to the constant of imposing a minimum time since arrest or conviction before allowing WCs to join the pool of workers. Columns 1--3 report results for the sample of hiring managers in the no wage subsidy sample. Columns 4--6 report results for the full sample of hiring managers that completed the experiment. Columns 1 and 4 report unweighted results for the restricted sample where the variables for firm size, industry type, and WC hiring policies are nonmissing. Columns 2 and 5 report results for the restricted sample reweighted to match the marginal distributions of the seven WC hiring policies from the nationwide survey commissioned by the SHRM. Columns 3 and 6 report results for the restricted sample reweighted to match the Infogroup Database industry shares." _n //
file write fh "All specifications report standard errors clustered by business in parentheses. " _n //
file write fh " " _n //
file write fh "$\dagger$ We use different values for crime and safety insurance (\\$1k and \\$5k) in two survey arms. " _n //
file write fh "For exposition, we pool the \\$1k and \\$5k insurance levels, which results in a uniform number of " _n //
file write fh "observations across values displayed under the label \emph{\\$5k}. }\\" _n //
file write fh "\end{tabular}" _n //
file write fh "\end{table} " _n //
file write fh "\end{landscape}" _n //


file close fh
macro drop fh	


/*===========================================================================
Appendix Table B.8: Robustness by Conviction Type
============================================================================*/

use "$Data/main_survey_longcrime.dta", clear

* Merge in subsample indicator variable
preserve
use "$Data/reweight_by_infogroup_industry_firmsize.dta", clear 
keep if subsample == 1 
keep mgr_id firm_id subsample
tempfile subsamp
save `subsamp'
restore 
merge m:1 mgr_id firm_id using `subsamp'	

* Merge in SHRM weights
preserve
use "$Data/reweight_by_infogroup_industry_firmsize.dta", clear 
keep if reweight_shrm == 1 
keep mgr_id firm_id weight 
rename weight weight_shrm
tempfile shrm
save `shrm'
restore 
drop _merge	
merge m:1 mgr_id firm_id using `shrm'	

* Merge in Infogroup weights
preserve
use "$Data/reweight_by_infogroup_industry_firmsize.dta", clear 
keep if reweight_info == 1 
keep mgr_id firm_id weight 
rename weight weight_info
tempfile info
save `info'
restore 

drop _merge		
merge m:1 mgr_id firm_id using `info'	

* Remove baseline observations since we are calculating effects relative to violent felony
gen no_conviction_restriction = violent_fel != 1 & prop_fin_fel != 1 & substance_fel != 1 & violent_mis != 1 & prop_fin_mis != 1 & substance_mis != 1 
drop if no_conviction_restriction == 1

* Calculate number of managers and firms for each robustness check
distinct mgr_id if subsample == 1 & subsidy_rate == 0
local n_mgrs_nosub_subsample = string(r(ndistinct), "%8.0fc")

distinct firm_id if subsample == 1 & subsidy_rate == 0
local n_firms_nosub_subsample = string(r(ndistinct), "%8.0fc")

distinct mgr_id if subsample == 1 
local n_mgrs_subsample = string(r(ndistinct), "%8.0fc")

distinct firm_id if subsample == 1 	
local n_firms_subsample = string(r(ndistinct), "%8.0fc")

** OLS regressions of treatment effects under different sample restrictions and weightings
* Unilateral Authority - no subsidy sample
local row=7
mat R=J(100,6,.)

* Subsample - no subsidy sample
reg hire violent_mis prop_fin_fel   ///
prop_fin_mis substance_fel substance_mis  if subsidy_rate == 0 & subsample == 1, cluster(firm_id)
foreach X in violent_mis prop_fin_fel prop_fin_mis substance_fel substance_mis _cons {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=2
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}	

* SHRM re-weighting - no subsidy sample
reg hire violent_mis prop_fin_fel   ///
prop_fin_mis substance_fel substance_mis  if subsidy_rate == 0 [aw=weight_shrm], cluster(firm_id)
foreach X in violent_mis prop_fin_fel prop_fin_mis substance_fel substance_mis _cons {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=3
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}

* Infogroup re-weighting - no subsidy sample
reg hire violent_mis prop_fin_fel   ///
prop_fin_mis substance_fel substance_mis  if subsidy_rate == 0 [aw=weight_info], cluster(firm_id)
foreach X in violent_mis prop_fin_fel prop_fin_mis substance_fel substance_mis _cons {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=4
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}

local row = `row' + 6

* Subsample - full sample
reg hire violent_mis prop_fin_fel   ///
prop_fin_mis substance_fel substance_mis  i.subsidy_rate if subsample == 1, cluster(firm_id)  
foreach X in violent_mis prop_fin_fel prop_fin_mis substance_fel substance_mis _cons {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=6
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}   

* SHRM re-weighting - full sample
reg hire violent_mis prop_fin_fel   ///
prop_fin_mis substance_fel substance_mis  i.subsidy_rate [aw=weight_shrm], cluster(firm_id)
foreach X in violent_mis prop_fin_fel prop_fin_mis substance_fel substance_mis _cons {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=7
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}   

* Infogroup re-weighting - full sample
reg hire violent_mis prop_fin_fel   ///
prop_fin_mis substance_fel substance_mis  i.subsidy_rate [aw=weight_info], cluster(firm_id)
foreach X in violent_mis prop_fin_fel prop_fin_mis substance_fel substance_mis _cons {
mat R[`row',1]=_b[`X']
mat R[`row',2]=_se[`X']
mat R[`row',4]=`row'
mat R[`row',5]=1
mat R[`row',6]=8
local coef_`row' = string(_b[`X'], "%10.3fc")
local sd_`row' = string(_se[`X'], "%10.3fc")
format 
local ++row
}	

clear	
svmat R
la var R1 "Willingness to Work with WCs (%)"

label define R5 1 "Conviction Type"
label values R5 R5

label define R6 1 "Restricted Sample - No Subsidy" 2 "Reweighted by WC Policy - No Subsidy" 3 "Reweighted by Industry Shares and Firm Size - No Subsidy" 4 "Restricted Sample - Full Sample" 5 "Reweighted by WC Policy - Full Sample" 6 "Reweighted by Industry Shares and Firm Size - Full Sample"
label values R6 R6

* Generate LaTeX file for the table
capture erase "$Tables/xt8_robustness_convictions.tex"
file open fh using "$Tables/xt8_robustness_convictions.tex", write append 	
file write fh "\begin{landscape}" _n //
file write fh "\begin{table}[htpb!]" _n //
file write fh " \vspace*{-1cm}" _n //
file write fh " \centering" _n //
file write fh "\captionsetup{justification=centering}" _n //
file write fh "\caption{ \\ Reweighted Results for Criminal Record Screening by Conviction Type}" _n //
file write fh "\label{table_robustness_convictions}" _n //
file write fh "\footnotesize\begin{tabular}{l c c c c c c c c c c c}" _n //
file write fh "\toprule " _n //
file write fh "& \multicolumn{5}{c}{No Subsidy Sample} && \multicolumn{5}{c}{Full Sample} \\" _n //
file write fh "\cline{2-6} \cline{8-12}" _n //
file write fh "\addlinespace" _n //
file write fh " & \multicolumn{1}{c}{} && \multicolumn{1}{c}{Reweighted} && \multicolumn{1}{c}{Reweighted} && \multicolumn{1}{c}{} && \multicolumn{1}{c}{Reweighted} && \multicolumn{1}{c}{Reweighted}  \\ " _n //
file write fh "&  \multicolumn{1}{c}{} && \multicolumn{1}{c}{by WC} && \multicolumn{1}{c}{by Industry} && \multicolumn{1}{c}{} && \multicolumn{1}{c}{by WC} && \multicolumn{1}{c}{by Industry}  \\ " _n //
file write fh "& \multicolumn{1}{c}{Restricted} && \multicolumn{1}{c}{Hiring} && \multicolumn{1}{c}{Shares and} && \multicolumn{1}{c}{Restricted} && \multicolumn{1}{c}{Hiring} && \multicolumn{1}{c}{Shares and}  \\ " _n //
file write fh "A. Crime and Safety Insurance & \multicolumn{1}{c}{Sample} && \multicolumn{1}{c}{ Policy} && \multicolumn{1}{c}{Firm Size} && \multicolumn{1}{c}{Sample} && \multicolumn{1}{c}{ Policy} && \multicolumn{1}{c}{Firm Size}  \\ " _n //
file write fh " \cline{2-2}\cline{4-4}\cline{6-6}\cline{8-8}\cline{10-10}\cline{12-12}" _n //
file write fh "\addlinespace" _n //
file write fh "\hspace{5 pt} Violent Misdemeanor & `coef_7' && `coef_13' && `coef_19' && `coef_31' && `coef_37' && `coef_43'  \\" _n //
file write fh "    	& (`sd_7') && (`sd_13') && (`sd_19') && (`sd_31') && (`sd_37') && (`sd_43')  \\" _n //
file write fh "\hspace{5 pt} Property Felony & `coef_8' && `coef_14' && `coef_20' && `coef_32' && `coef_38' && `coef_44'   \\" _n //
file write fh "     & (`sd_8') && (`sd_14') && (`sd_20') && (`sd_32') && (`sd_38') && (`sd_44')   \\" _n //
file write fh "\hspace{5 pt} Property Misdemeanor & `coef_9' && `coef_15' && `coef_21' && `coef_33' && `coef_39' && `coef_45'   \\" _n //
file write fh "     & (`sd_9') && (`sd_15') && (`sd_21')  && (`sd_33') && (`sd_39') && (`sd_45')   \\" _n //
file write fh "\hspace{5 pt} Drug Felony & `coef_10' && `coef_16' && `coef_22'  && `coef_34' && `coef_40' && `coef_46'   \\" _n //
file write fh "     & (`sd_10') && (`sd_16') && (`sd_22') && (`sd_34') && (`sd_40') && (`sd_46')   \\" _n //
file write fh "\hspace{5 pt} Drug Misdemeanor & `coef_11' && `coef_17'  && `coef_23' && `coef_35' && `coef_41' && `coef_47'  \\" _n //
file write fh "     & (`sd_11') && (`sd_17') && (`sd_23') && (`sd_35') && (`sd_41') && (`sd_47')   \\" _n //
file write fh "\hspace{5 pt} Constant & `coef_12' && `coef_18' && `coef_24' && `coef_36' && `coef_42' && `coef_48'   \\" _n //
file write fh "     & (`sd_12') && (`sd_18') && (`sd_24') && (`sd_36') && (`sd_42') && (`sd_48')   \\" _n //
file write fh "\addlinespace" _n //
file write fh "\hline" _n //
file write fh "\addlinespace" _n //
file write fh "Firms       & `n_firms_nosub_subsample' && `n_firms_nosub_subsample' && `n_firms_nosub_subsample'  && `n_firms_subsample' && `n_firms_subsample' && `n_firms_subsample'       \\" _n //
file write fh "Managers    & `n_mgrs_nosub_subsample' && `n_mgrs_nosub_subsample' && `n_mgrs_nosub_subsample' && `n_mgrs_subsample' && `n_mgrs_subsample' && `n_mgrs_subsample'   \\" _n //
file write fh "\bottomrule" _n //
file write fh "\end{tabular}" _n //
file write fh "\begin{tabular}{ p{\linewidth}}" _n //
file write fh "\scriptsize{\hspace{1em}{\emph{Notes.}} This table reports OLS estimates of the effects of restricting WCs to those with a given crime type on firms' willingness to work with workers with a criminal record using different samples and weighting methods. The constant is the estimate for the mean willingness to work with WCs if the Platform restricts WCs to those with a violent felony conviction. Each reported estimate is relative to the constant. Columns 1--3 report results for the sample of" _n //
file write fh "hiring managers in the no wage subsidy sample. Columns 4--6 report results for the full sample of hiring managers that completed the experiment. Columns 1 and 4 report unweighted results for the restricted sample where the variables for firm size, industry type, and WC hiring policies are nonmissing. Columns 2 and 5 report results for the restricted sample reweighted to match the marginal distributions of the seven WC hiring policies from the nationwide survey commissioned by the SHRM. Columns 3 and 6 report results for the restricted sample reweighted to match the Infogroup Database industry shares. All specifications report standard errors clustered by business in parentheses. }\\" _n //
file write fh "\end{tabular}" _n //
file write fh "\end{table} " _n //
file write fh "\end{landscape}" _n //


file close fh
macro drop fh	

log close
exit
